﻿using System;

namespace LoongEgg.Check
{
    /// <summary>
    /// UInt64的扩展方法
    /// </summary>
    public static class UInt64Extensions
    { 
        /// <summary>
        /// reflect:1100-1110-1010-0000 ->  0000-0101-0111-0011
        /// </summary>
        /// <param name="valueLength">the bits length to reflect</param>
        /// <returns>镜像后的64位无符号整形</returns>
        public static UInt64 ReflectBits(this UInt64 self, int valueLength = 64)
        {
            ulong reflect = 0;

            for (int i = valueLength - 1; i >= 0; i--)
            {
                reflect |= (self & 1) << i;
                self >>= 1;
            }

            return reflect;
        }
    }
}
